package com.hspedu.springboot.controller;

import com.hspedu.springboot.bean.Monster;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.Cookie;
import java.util.List;
import java.util.Map;

@RestController
public class ParameterController {
    @RequestMapping("/monster/{id}/{name}")
    public String pathVarible(@PathVariable("id")Integer id,
                              @PathVariable("name")String name,
                              @PathVariable Map<String,String> map) {
        System.out.println("id-"+id);
        System.out.println("name-"+name);
        System.out.println("map-"+map);
        return "success";
    }
    @RequestMapping("/requestHeader")
    public String requestHeader(@RequestHeader("Host") String host,
                                @RequestHeader Map<String,String > map){
        System.out.println("host==="+host);
        System.out.println("map==="+map);
        return "success";
    }
    @RequestMapping("/hi")
    public String requestHeader(@RequestParam(value = "name",required = false) String name,
                                @RequestParam(value = "fruit",required = false)List<String> fruits){
        System.out.println("name==="+name);
        System.out.println("fruits==="+fruits);
        return "success";
    }
    @GetMapping("/cookie")
    public String cookie(@CookieValue(value = "cookie_key",required = false)String cookie_key,
                         @CookieValue(value = "username",required = false)Cookie cookie){
        System.out.println("cookie_key----"+cookie_key);
        if (cookie!=null){
            System.out.println("cookie----"+cookie.getName()+"---"+cookie.getValue());
        }
        return "success";
    }
    @PostMapping("/save")
    public String save(@RequestBody String context){
        System.out.println("context----"+context);
        return "success";
    }
@PostMapping("/saveMonster")
    public String saveMonster(Monster monster){
    System.out.println("monster=-------------"+monster);
    return "success";
    }

}
